<?php

namespace api\controller;

use common\controller\VerifyController;
use common\service\OptionsService;
use think\Request;
use think\Response;

class OptionsController extends VerifyController
{
    /**
     * @var OptionsService
     */
    protected $optionsService;


    public function __construct()
    {
        parent::__construct();
        $this->optionsService = OptionsService::getInstance();
    }

    /**
     * 添加配置
     * @param Request $request
     * @return Response
     */
    public function create(Request $request)
    {
        $param = $request->param();
        $resData = $this->optionsService->addOptionsData($param['data']);
        return json($resData);
    }

    /**
     * 修改options
     * @param Request $request
     * @return Response
     */
    public function update(Request $request)
    {
        $param = $request->param();
        $resData = $this->optionsService->updateOptionsData($param['data']);
        return json($resData);
    }

    /**
     * 获得指定名称的配置
     * @param Request $request
     * @return Response
     */
    public function getOptions(Request $request)
    {
        $param = $request->param();
        $resData = $this->optionsService->getOptionsData($param["options_name"]);
        return json(success_response('', $resData));
    }

    /**
     * 获得指定名称的配置
     * @param Request $request
     * @return Response
     */
    public function getOptionsItem(Request $request)
    {
        $param = $request->param();
        $resData = $this->optionsService->getOptionsConfigItemData($param["options_name"], $param["options_item_name"]);
        return json(success_response('', $resData));
    }
}
